home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / MenuMadness / Source / C Source / AppMain.c next >
Encoding:
C/C++ Source or Header  |  1996-06-21  |  1.7 KB  |  118 lines  |  [TEXT/CWIE]

  1. /* This app is just a shell, so we can test the MenuSelect code more easily
  2.  
  3. */
  4.  
  5.  
  6. #include <QDOffscreen.h>
  7. #include <string.h>
  8.  
  9. #include "MenuSelect.h"
  10.  
  11. OSErr    DoMenu(long    menuCode);
  12. OSErr    DoMouseDown(EventRecord*    theEvent);
  13. void     main(void);
  14. OSErr    DoEvent(EventRecord*    theEvent);
  15. OSErr    SetupMenus(void);
  16.  
  17.  
  18. static void InitToolbox(void)
  19. {
  20.     
  21.     MaxApplZone();
  22.     MoreMasters();
  23.     MoreMasters();
  24.  
  25. /* Initialize the various Managers */   
  26.     InitGraf(&qd.thePort);
  27.     InitFonts();
  28.     FlushEvents(everyEvent, 0);
  29.     InitWindows();
  30.     InitDialogs(nil);
  31. }
  32.  
  33.  
  34. void main(void)
  35. {
  36.     EventRecord    theEvent;
  37.  
  38.     InitToolbox();
  39.     
  40.     SetupMenus();
  41.     DrawMenuBar();
  42.  
  43.     while(1)
  44.         {
  45.         WaitNextEvent(everyEvent, &theEvent, 0, nil);
  46.         DoEvent(&theEvent);
  47.         }
  48. }
  49.  
  50.  
  51. OSErr    SetupMenus(void)
  52. {
  53.     MenuHandle    appleMenu = nil;
  54.     
  55.     SetMenuBar(GetNewMBar(128));
  56.     
  57.     AddResMenu(GetMenuHandle(1), 'DRVR');
  58.     
  59. }
  60.  
  61.  
  62. OSErr    DoEvent(EventRecord*    theEvent)
  63. {
  64.     switch(theEvent->what)
  65.         {
  66.         case mouseDown:
  67.             return DoMouseDown(theEvent);
  68.             break;
  69.         }
  70. }
  71.  
  72. OSErr    DoMouseDown(EventRecord*    theEvent)
  73. {
  74.     OSErr        result = noErr;
  75.     WindowPtr    w = nil;
  76.     short        theType = FindWindow(theEvent->where, &w);
  77.     long        menuResult = 0;
  78.     
  79.     switch(theType)
  80.         {
  81.         case inMenuBar:
  82.             menuResult = AltMenuSelect(theEvent->where, kFXSlide, kFXZoomIn);
  83.             
  84.             if (menuResult)
  85.                 result = DoMenu(menuResult);
  86.             break;
  87.         default:
  88.             ExitToShell();
  89.             break;
  90.         }
  91.     
  92.     return result;
  93. }
  94.  
  95. enum {kAppleMenuID = 1, kFileMenuID, kEditMenuID};
  96.  
  97. OSErr    DoMenu(long    menuCode)
  98. {
  99.     short    menuID = menuCode >> 16;
  100.     short    menuItem = menuCode & 0xFF;
  101.     OSErr    result = noErr;
  102.     
  103.     switch(menuID)
  104.         {
  105.         case kAppleMenuID:
  106.             
  107.             break;
  108.             
  109.         case kFileMenuID:
  110.             ExitToShell();
  111.             break;
  112.         }
  113.         
  114.     return result;
  115. }
  116.  
  117.  
  118.